package com.scu.baseline.controller;



import com.scu.baseline.pojo.Department;
import com.scu.baseline.service.impl.DepartmentServiceImpl;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Department)表控制层
 *
 * @author AlonBurukeses
 * @since 2022-06-23 09:14:21
 */
@RestController
@Api(value = "部门数据接口",tags = "部门数据接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
@RequestMapping("department")
public class DepartmentController {
    /**
     * 服务对象
     */
    @Resource
    private DepartmentServiceImpl departmentServiceimImpl;
    @ApiOperation(value = "部门查询接口",notes = "部门查询接口",httpMethod = "GET")
    @RequestMapping(value = "/findalldepartment",method = RequestMethod.GET)
    public Map<String,Object> findAllDepartment() {
        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("msg","查询成功");
        map.put("res",this.departmentServiceimImpl.selectall());
        return map;
    }
    @ApiOperation(value = "部门查询接口",notes = "部门查询接口",httpMethod = "GET")
    @RequestMapping(value = "/finddepartmentbyname",method = RequestMethod.GET)
    public Map<String,Object> finddepartmentbyname(@RequestParam(value = "name")String name) {
        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("msg","查询成功");
        map.put("res",this.departmentServiceimImpl.selectByName(name));
        return map;
    }
    @ApiOperation(value = "部门查询接口",notes = "部门查询接口",httpMethod = "GET")
    @RequestMapping(value = "/finddepartmentbypage",method = RequestMethod.GET)
    public Map<String,Object> finddepartmentbypage(@RequestParam(value = "page")Integer page) {
        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("msg","查询成功");
        map.put("res",this.departmentServiceimImpl.selectByPage(page));
        return map;
    }
    @ApiOperation(value = "部门添加接口",notes = "部门添加接口",httpMethod = "POST")
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public Map<String,Object> insert(@RequestBody Map data) {
        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("msg","添加成功");
        this.departmentServiceimImpl.insertbymap(data);
        return map;
    }
    @ApiOperation(value = "部门删除接口",notes = "部门删除接口",httpMethod = "GET")
    @RequestMapping(value = "/deletebyid",method = RequestMethod.GET)
    public Map<String,Object> deletebyid(@RequestParam(value = "id")Integer id) {
        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("msg","删除成功");
        this.departmentServiceimImpl.deleteById(id);
        return map;
    }
    @ApiOperation(value = "部门更新接口",notes = "部门更新接口",httpMethod = "POST")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Map<String,Object> update(@RequestBody Map data) {
        Map<String,Object> map = new HashMap();
        map.put("code",200);
        map.put("msg","修改成功");
        this.departmentServiceimImpl.updatebymap(data);
        return map;
    }
}

